﻿using System;
using System.Linq.Expressions;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 比较方式枚举的扩展
        /// </summary>
        public static class CompareTypeExtension
        {
                /// <summary>
                /// 将比较方式枚举转换为Lambda表达式类型枚举
                /// </summary>
                /// <param name="compareType">比较方式枚举</param>
                /// <exception cref="ArgumentOutOfRangeException"></exception>
                /// <returns>Lambda表达式类型枚举</returns>
                /// <exception cref="System.ArgumentOutOfRangeException">比较模式转换失败</exception>
                public static ExpressionType ConvertToExpressionType(this CompareType compareType)
                {
                        switch (compareType)
                        {
                                case CompareType.大于:
                                        return ExpressionType.GreaterThan;

                                case CompareType.大于等于:
                                        return ExpressionType.GreaterThanOrEqual;

                                case CompareType.等于:
                                        return ExpressionType.Equal;

                                case CompareType.小于等于:
                                        return ExpressionType.LessThanOrEqual;

                                case CompareType.小于:
                                        return ExpressionType.LessThan;

                                case CompareType.不等于:
                                        return ExpressionType.NotEqual;

                                default:
                                        throw new ArgumentOutOfRangeException("比较模式转换失败");
                        }
                }
        }
}